package vn.edu.saigontech.ncms.web.student;

import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidatePlacementTestAction extends AbstractValidator {
	
	private Long id;
	private String date;
	private String writtenScore;
	private String speakingScore;
	private String fee;
	
	private boolean editAll = false;
	private Long[] ids;
	private String[] dates;
	private String[] writtenScores;
	private String[] speakingScores;
	
	public String check() {
		if(!this.editAll) {
			this.check0(this.id, this.date, this.writtenScore, this.speakingScore, this.fee);
		}
		else {
			for(int i = 0; i < this.ids.length; i++) {
				this.check0(null, this.dates[i], this.writtenScores[i], this.speakingScores[i], null);
			}
		}
		return this.toSuccess();
	}

	private void check0(Long _id, String _date, String _writtenScore, String _speakingScore, String _fee) {
		if(Checker.isEmpty(_date)) {
			this.sendKeyError("validator.required", "date");
		}
		if(!Checker.isDate(_date, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "date", "format.date");
		}
		if(Checker.isEmpty(_writtenScore)) {
			_writtenScore = "0";
		}
		if(!Checker.isDouble(_writtenScore) || !Checker.isInRange(Double.valueOf(_writtenScore), 0, 100)) {
			this.sendKeyError("validator.invalid", "writtenScore");
		}
		if(Checker.isEmpty(_speakingScore)) {
			_speakingScore = "0";
		}
		if(!Checker.isDouble(_speakingScore) || !Checker.isInRange(Double.valueOf(_speakingScore), 0, 100)) {
			this.sendKeyError("validator.invalid", "speakingScore");
		}
		if(!Checker.isEmpty(_fee)) {
			if(!Checker.isDouble(_fee)) {
				this.sendKeyError("validator.invalid", "fee");
			}
		}
	}
	
	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getWrittenScore() {
		return writtenScore;
	}

	public void setWrittenScore(String writtenScore) {
		this.writtenScore = writtenScore;
	}

	public String getSpeakingScore() {
		return speakingScore;
	}

	public void setSpeakingScore(String speakingScore) {
		this.speakingScore = speakingScore;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public boolean isEditAll() {
		return editAll;
	}

	public void setEditAll(boolean editAll) {
		this.editAll = editAll;
	}

	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}

	public String[] getDates() {
		return dates;
	}

	public void setDates(String[] dates) {
		this.dates = dates;
	}

	public String[] getWrittenScores() {
		return writtenScores;
	}

	public void setWrittenScores(String[] writtenScores) {
		this.writtenScores = writtenScores;
	}

	public String[] getSpeakingScores() {
		return speakingScores;
	}

	public void setSpeakingScores(String[] speakingScores) {
		this.speakingScores = speakingScores;
	}

	public String getFee() {
		return fee;
	}

	public void setFee(String fee) {
		this.fee = fee;
	}
}
